import { configureStore } from "@reduxjs/toolkit";
import routerModulesReduce from "./routerModulesSlice";
import { apiSlice } from './apiSlice';
import { listenerMiddleware } from './listenerMiddleware';
import { setupListeners } from "@reduxjs/toolkit/query";

export const store = configureStore({
    reducer: {
        routerModules: routerModulesReduce,
        [apiSlice.reducerPath]: apiSlice.reducer,
    },
    middleware: getDefaultMiddleware =>
        getDefaultMiddleware({
            //关闭redux序列化检测
            serializableCheck: false
        })//默认的中间件
            .prepend(listenerMiddleware.middleware)
            .concat(apiSlice.middleware)//应用RTK Query缓存
});
setupListeners(store.dispatch);//设置后，将会支持refetchOnFocus、refetchOnReconnect
// refetchOnFocus: false, //是，是否在重新获取焦点时重载数据
// refetchOnReconnect: false, //是否在断线后重新加载数据

export type AppStore = typeof store;
// 从 store 本身推断出 `RootState` 和 `AppDispatch` 类型
export type RootState = ReturnType<AppStore['getState']>;
export type AppDispatch = AppStore['dispatch'];